import { request, WXShowToast, WXNavigateTo, WXshowToast } from '../../utils/index.js';
import { Api } from '../../config/api.js';
var appInst = getApp();

Page({
  data: {
    host: appInst.globalData.host,
    good: null,
    goodid:null,
    nodes: ''
  },
  onLoad: function (options) {
    this.getGoodDetails(options.goodid);
    this.setData({
        goodid: options.goodid
    })
  },

async  getGoodDetails(goodid) {
    const {data} = await   request({
        url: Api.getGoodDetails,
        data: { id: goodid },
        method: 'POST'
        })
    
    this.setData({
        good:data.data
    })
    var article = data.data.contents;
    var that = this;
    let da = data.data.contents  //富文本
    that.setData({
        nodes: da
    })
    data.data.goodNum = 1
    let goodlist =[]
    goodlist.push(data.data)
    wx.setStorageSync('goodlist', goodlist);
},

// 添加购物车
async addCart() {
       const {data} = await   request({
                url: Api.addCart,
                data: { goods_id: this.data.goodid },
                method: 'POST'
    })
    if(data.code==2001){
        wx.navigateTo({
                url: '/pages/cart/cart'
         });
    }else if(data.code ==1001){
        WXshowToast("您不是会员不能购买本区商品")
    }
},

    handleBuy() {
        wx.setStorageSync('gmtype',1)//1 商品立即购买
        WXNavigateTo('/pages/place_order/place_order')
            
    }
});
